package com.gitee.feizns.web.ex;

import com.gitee.feizns.StringUtils;
import com.gitee.feizns.web.domain.result.Ret;
import org.springframework.http.ResponseEntity;

/**
 * @author feizns
 * @since 2019/7/7
 */
@FunctionalInterface
public interface CustomizeExceptionHandler<E extends Throwable, D> {

    /**
     * 异常处理
     * @param e
     * @return
     */
    ResponseEntity<Ret<D>> handle(E e);

    /**
     * 默认类名前缀转常量
     * @param e
     * @return
     */
    static String defaultMsg(Throwable e) {
        return StringUtils.toUnderline(e.getClass().getSimpleName().replace("Exception", "")).toUpperCase();
    }

}

